package org.example.sudoku;
import java.text.BreakIterator;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;

;

public class Sudoku extends Activity implements OnClickListener {

    private static final String TAG="Sudoku";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		View aboutButton = findViewById(R.id.about_button);
		aboutButton.setOnClickListener(this);
		
		View exitButton = findViewById(R.id.exit_button);
		exitButton.setOnClickListener(this);
		
		View newButton = findViewById(R.id.new_game_button);
		newButton.setOnClickListener(this);
		
		View continueButton = findViewById(R.id.continue_button);
		continueButton.setOnClickListener(this);
	}
    @Override
    protected void onResume() {
    	// TODO Auto-generated method stub
    	super.onResume();
    	Music.play(this, R.raw.main);
    }
    @Override
    protected void onPause() {
    	// TODO Auto-generated method stub
    	super.onPause();
    	Music.stop(this);
    }
	private void startGame(int i) {
		Log.d(TAG, "startGame click on"+i);
		Intent intent =new Intent(this,Game.class);
		
		intent.putExtra(Game.KEY_DIFFICULTY, i);
		startActivity(intent);
	}
	private void openNewGameDialog() {
		// TODO Auto-generated method stub

		new AlertDialog.Builder(this)
		.setTitle(R.string.new_game_title)
		.setItems(R.array.difficulty, new DialogInterface.OnClickListener(				
				) {
			
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				// TODO Auto-generated method stub
				startGame(arg1);
			}
		}).show();
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.continue_button:
			startGame(Game.DIFFICULTY_CONTINUE);
			break;
     
		case R.id.new_game_button:
			openNewGameDialog();
			break;
		case R.id.about_button:
			Intent intent = new Intent(this, About.class);
			startActivity(intent);
			break;
			
		case R.id.exit_button:	
			Log.i(TAG, "exit_button clicked");
			finish();
			break;

		default:
			break;
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
	 case R.id.menu_settting:
		  startActivity(new Intent(this,Prefs.class));
		 break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}


}
